package com.doit.day04

import scala.collection.mutable
import scala.collection.mutable.{ArrayBuffer, ListBuffer}

object _08_可变集合 {
  def main(args: Array[String]): Unit = {
    //可变数组
    val ints: ArrayBuffer[Int] = new ArrayBuffer[Int]()
    ints.append(1,2,3,4)
    println(ints)

    ints.insert(2,10,20,30)
    println(ints)

    val arr: Array[Int] = Array(100, 200)
    ints.insertAll(1,arr)
    println(ints)// 1 100 200 2 10 20 30 3 4

    ints.remove(1)//删除索引为1的元素
    println(ints)//ArrayBuffer(1, 200, 2, 10, 20, 30, 3, 4)

    ints.remove(1,2)
    println(ints)//ArrayBuffer(1, 10, 20, 30, 3, 4)

    println(ints(1))//10

    //list的可变集合
    val list: ListBuffer[Int] = new ListBuffer[Int]()


    //到了set和map就不一样了
    val ints1: mutable.Set[Int] = mutable.Set( 2, 3, 4)
    ints1.add(10)
    ints1.add(20)
    ints1.add(130)

    ints1.update(1,included = true)
    println(ints1)

    ints1.remove(10)//删除10这个元素

    ints1.apply(1)//判断元素存在还是不存在

    //Map
    val map: mutable.Map[Int, String] = mutable.Map()
    map.put(1,"zss")
    map.remove(1)
    val maybeString: Option[String] = map.get(1)
    val str: String = map.getOrElse(1, "aa")





















  }
}
